$(function(){ 
            var url = 'http://127.0.0.1:3000/todo/get';
            $.getJSON(url, render); 
});

function render(tasks){
      
    var itemTemplate = $('#tasks tbody').html();
    $('#tasks tbody').html('{$}');
    var setTemplate = $('#tasks').html();
    var rules = {
        'self':function(tasks){ return (tasks && tasks.length) ? setTemplate : ''; },
        'self[*]':itemTemplate,
        'self[*].done': function(done){ return done ? 'checked="true"' : ''},
        'self[*].tasks': function(tasks){ return jsonT(tasks, rules); }
    };
    $('#tasks').html(jsonT(translate(tasks), rules));
    
}

function translate(tasks, superNumber){
    var array = [];
    $.each(tasks, function(name, task){
        var index = array.length;
        var number = (superNumber ? superNumber + '.' : '') + (index + 1);
        var tasks = task.tasks && translate(task.tasks, number);
        array.push({name:name, 
                    number:number,
                    tasks: tasks,
                    done:task.done,
                    start:task.start,
                    end:task.end});
    });
    return array;
}